package webService.implementation;

import java.awt.List;
import java.util.Date;
import java.util.HashMap;

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;


import webService.interfaces.IWSPaiement;
import webService.util.CompteDTO;
import webService.util.Devise;
import webService.util.EtatTransaction;
import webService.util.JetonRetour;
import webService.util.TransactionDTO;

@Stateless
@WebService(name="WSPaiement")
public class WSPaiement implements IWSPaiement{

	public static HashMap<String, TransactionDTO> transactions = new HashMap<String, TransactionDTO>();
	public static HashMap<String, CompteDTO> comptes = new HashMap<String, CompteDTO>();
	
	static {
		
		comptes.put("ecommerce", new CompteDTO("ecommerce", "123", "123", new Date(2000,12,12), 100, "guion.alexandre@live.fr"));
		comptes.put("toto", new CompteDTO("toto", "123", "123", new Date(2000,12,12), 0, "guion.alexandre@live.fr"));
		comptes.put("pognon", new CompteDTO("pognon", "123", "123", new Date(2000,12,12), 100000, "guion.alexandre@live.fr"));
		
		transactions.put("42", new TransactionDTO("42", EtatTransaction.ENCOURS, 100, Devise.EURO, comptes.get("ecommerce"),null, "www.google.fr", 30L ));
		
	}
	
	
	@WebMethod
	public JetonRetour ouvertureTransaction(double somme, Devise devise,
			CompteDTO compteACrediter, String urlRetour, Long timeOut) {

		JetonRetour leJeton = new JetonRetour();
		leJeton.setUrlRedirection("192.168.11.150:9090/WebServicePaiement-web-0.0.1-SNAPSHOT/saisieCarte.xhtml?uuid=" + leJeton.getUuidRequete());
		
		transactions.put(leJeton.getUuidRequete(), new TransactionDTO(leJeton.getUuidRequete(), EtatTransaction.ENCOURS, somme, devise, compteACrediter, null, urlRetour, timeOut));
		System.out.println(leJeton.getUuidRequete() + "luidd de requete a mettre");							
		return leJeton;
	}

	@WebMethod
	public EtatTransaction pollingEtat(String uuidTransaction) {
		
		return transactions.get(uuidTransaction).getEtatTransaction();
	}

}
